<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/header.css" />
	</head>

	<body>

		<header class="mui-bar mui-bar-nav title">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
			<a id="link_submit_edit" class="mui-icon mui-icon-right-nav mui-pull-right" 
							style="color: white;font-size: 14px;line-height: 27px;">提交</a>
			<h1 class="mui-title title-color">编辑用户信息</h1>
		</header>

		<div class="mui-content">
			<div class="mui-card">
				<div class="mui-input-row">
					<label>用户账号</label>
					<input id="link_user_id" type="text" class="mui-input-clear" placeholder="请输入用户账号" readonly="true">
				</div>
				<div class="mui-input-row">
					<label>用户昵称</label>
					<input id="link_user_name" type="text" class="mui-input-clear" placeholder="请输入用户昵称">
				</div>
				<div class="mui-input-row">
					<label>班级id</label>
					<input id="link_class_id" type="text" class="mui-input-clear" placeholder="请输入班级id">
				</div>
			</div>
		
		</div>

		<script src="../../js/mui.min.js"></script>
		<script src="../../js/app.js"></script>
		<script type="text/javascript">
			mui.init()

			mui.plusReady(function() {
				var user = app.getGlobalUserInfo();
				
				// 获取当前页面webview
				var userEditWebview = plus.webview.currentWebview();
				
				// 获取上一个页面传入的值
				var userId = userEditWebview.userId;
				var userName = userEditWebview.userName;
				var classId = userEditWebview.classId;
				
				var link_user_id = document.getElementById("link_user_id");
				var link_user_name = document.getElementById("link_user_name");
				var link_class_id = document.getElementById("link_class_id");
				
				link_user_id.value = userId;
				link_user_name.value = userName;
				link_class_id.value = classId;
				
				var link_submit_edit = document.getElementById("link_submit_edit");
				link_submit_edit.addEventListener("tap",function(){
					mui.ajax(app.serverUrl + "/user/admin/update_userinfo?user_id=" + userId
								+ "&name=" + link_user_name.value
								+ "&class_id=" + link_class_id.value, {
						data: {},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						headers: {
							'Content-Type': 'application/json'
						},
						success: function(data) {
							if (data.status == 200) {
								app.showToast("用户信息已成功修改！", "success");
								mui.openWindow({
									url: "userInfo.html", 
									id: "userInfo.html",
									createNew: true,
								});
							} else {
								app.showToast("获取数据失败，请重试！", "error");
							}
						}
					});
				});
				
			});
		</script>
	</body>

</html>